home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef __DATARECORD__
- #define __DATARECORD__
-
- //
- // For class TAbstractRecord
- //
- #include "AbstractRecord.h"
-
- //
- // Data Records:
- //
- // Fields
- //
- // Flag word
- // Reference to owner
- //
- // All following words contain data
- //
- // Bits in flag word:
- //
- // b31-b30: Zero indicates a data record (Non-zero indicates a database record)
- // b29-b24: 0x3F == a free block, anything else == a used block
- // b23-b16: Encoded block physical size
- // b15-b8: Previous block's physical size (or 0 for first block in group)
- // b7-b0: Block size correction
- //
-
- enum
- {
- kDataFlags = 0, // Flags stored in longword zero, as always
- kDataOwnerReference = 1, // Reference to record that owns this data in longword 1
- kHeaderSize = 8, // Number of bytes in header == 2 longwords
- kDataStorageStart = 2, // Real data starts at longword 2
- kDataBlockSizeCorrection = 0x000000FF, // Physical size - sizeof(header) - size correction == length of data
- kDataBlockSizeCorrectionShift = 0,
- kInitialDataBlockFlagsMask = 0x00FFFFFF, // Zero bits in this mask are used to clear bits in flag word when new data block is initialized
- kInitialDataBlockFlagsWord = 0 // Temporary, to pass in when making a new record
- };
-
- //================================================================================
- // Class TDataRecord
- //================================================================================
- class TDataRecord : public TAbstractRecord
- {
- //
- // ----- Fields --------------------------------------------------------------
- //
- protected:
- AConst<TDBProperty> fDataOwner;
- long fChangeImageSize;
- Boolean fDataReleased;
- long fOriginalRecordIndex;
-
- //
- // ----- Methods -------------------------------------------------------------
- //
-
- public:
- TDataRecord(TDatabaseDocument* doc, long recordIndex) :
- TAbstractRecord(doc, recordIndex), fDataOwner(nil), fChangeImageSize(0), fDataReleased(false), fOriginalRecordIndex(recordIndex)
- {
- //
- // Note: we know that we never need a transaction pointer here
- // because this object would already be constructed if its
- // data had changed on some transaction.
- //
- // ◊Will this be true in the future, though? Actually, fDataOwner
- // might be a different record on a different transaction. We
- // should probably cache two completely different data owner
- // objects, one for the active transaction, and one for the
- // unchanged object. Either that or look up the data owner each
- // time it's needed (perhaps preferable)
- //
- fDataOwner = this->GetDBPropertyCursor(this->DataOwnerIndex(nil));
- };
- virtual ~TDataRecord();
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Overrides of TTransactionAwareObject:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- virtual void PrepareToCommit(TTransaction* t);
- virtual void CommitChanges(TTransaction* t);
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Overrides of TAbstractRecord:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Methods of TDataRecord:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- virtual const TDataRecord* DataRecord() const { return this; };
- // virtual TDataRecord* DataRecord() const { return this; };
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public interface: const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
- long GetDataType(TTransaction* t) const;
- long GetDataLength(TTransaction* t) const;
- long MaximumDataLength(TTransaction* t) const;
-
- void GetTypedData(TTransaction* t, TAbstractDataReference& data) const;
-
- //
- // Used by TDBProperty::Verify
- //
- long DataOwnerIndex(TTransaction* t) const { return this->GetRecordData(t, kDataOwnerReference); }
-
- //
- // Do debugging tests on this node
- //
- virtual void Verify(TTransaction* t, Boolean verifyDeep = false) const;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public interface: non-const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- void ReleaseData(TTransaction* t);
- void SetDataOwner(TTransaction* t, AnUpdate<TDBProperty> dataOwner);
-
- void SetTypedData(TTransaction* t, const TAbstractDataReference& data);
-
- //
- // Usually, only a property record will ever create a data record
- //
- void InitializeNewDataRecord(TTransaction* t);
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Protected interface: const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- long BlockEncodedPhysicalSize(TTransaction* t) const;
- long BlockPhysicalSize(TTransaction* t) const;
- long SizeCorrection(TTransaction* t) const;
-
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Protected interface: non-const methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- void SetSizeCorrection(TTransaction* t, long sizeCorrection);
- void SetBlockEncodedPhysicalSize(TTransaction* t, long blockPhysicalSize);
- void SetLogicalSize(TTransaction* t, long logicalSize);
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Private methods:
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- public:
-
- //
- // Only to be called to do a comparison
- //
- TConstDataReference DataReference(TTransaction* t) const;
-
- };
-
- #endif
-